﻿using Lucene.Net.Analysis;
using Lucene.Net.Documents;
using Lucene.Net.Index;
using Lucene.Net.Search;
using Lucene.Net.Store;
using Lucene.Net.Util;
using MiniExcelLibs;
using System.Text;
using ToWangKeLib;

//var isLogin = ChaoXing.Login("17760036785", "zj666@qq.com");

//if (isLogin)
//{
//string html = File.ReadAllText("work.txt");

//ChaoXing.GetFinishCourse("形策",html);
//ChaoXing.GetFinishCourse("https://mooc1.chaoxing.com/mooc2/work/view?courseId=219628469&classId=47920162&cpi=147551691&workId=16632324&answerId=50910467&enc=b6b5fe35bfd13bd912f189c4f6dd1779");
//Console.WriteLine("sdf");
//}

//ChaoXing.GetVideoUrl("http://qr.cmpedu.com/CmpBookResource/show_resource.do?id=88035");

//for (int i = 33; i < 125; i++)
//{
//    if (i <= 99)
//    {
//        ChaoXing.GetVideoUrl("http://qr.cmpedu.com/CmpBookResource/show_resource.do?id=880" + i);
//    }
//    else if (i >= 100)
//    {
//        ChaoXing.GetVideoUrl("http://qr.cmpedu.com/CmpBookResource/show_resource.do?id=88" + i);
//    }
//    Console.WriteLine($"获取第{i}个");
//}

//Console.WriteLine("===================");

//var books = ChaoXing.GetBooksName();
//int count = books.Length;


//for (int j = 0; j < count; j++)
//{
//    var ite = books[j].Trim().Replace("\r\n", "");
//    for (int i = 0; i < count; i++)
//    {
//        var item = ChaoXing.VideoNameList[i];
//        if (ite.Equals(item.Trim()))
//        {
//            //ChaoXing.DownLoad_Video(ChaoXing.VideoUrlList[i], item, $"{j + 1}");
//            Console.WriteLine($"{j + 1} => {item} = {ChaoXing.VideoUrlList[i]}");
//        }
//    }
//}


//for (int i = 0; i < ChaoXing.VideoUrlList.Count; i++)
//{
//    ChaoXing.DownLoad_Video(ChaoXing.VideoUrlList[i], ChaoXing.VideoNameList[i], $"{i + 1}");
//    Console.WriteLine($"{i + 1} = {ChaoXing.VideoNameList[i]} = {ChaoXing.VideoUrlList[i]}");
//}


var rows = MiniExcel.Query<VideoInfo>($"{AppDomain.CurrentDomain.BaseDirectory}PDPS视频网址.xlsx", "Sheet2").ToList();

foreach (var item in rows)
{
    string videoStr = ChaoXing.GetVideoUrl(item.Url);
    ChaoXing.DownLoad_Video(videoStr, item.Name, $"{item.Index}");
    Console.WriteLine($"下载第{item.Index}个:{item.Name}:{videoStr}");
}

Console.ReadKey();


public class VideoInfo
{
    public string Index { get; set; }
    public string Name { get; set; }
    public string Url { get; set; }
}